Skip to content

[SPARK-57500][SQL] Escape backslash in MySQL JDBC pushdown for string literals in comparison/IN predicates#56558

Draft
jiwen624 wants to merge 1 commit into
apache:masterfrom
jiwen624:SPARK-mysql-backslash-literal-pushdown
Draft

[SPARK-57500][SQL] Escape backslash in MySQL JDBC pushdown for string literals in comparison/IN predicates#56558
jiwen624 wants to merge 1 commit into
apache:masterfrom
jiwen624:SPARK-mysql-backslash-literal-pushdown

Conversation

@jiwen624

@jiwen624 jiwen624 commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

MySQL treats \ as an escape character inside string literals. MySQLDialect.escapeSql now doubles backslashes (on top of the base single-quote doubling). To avoid double-escaping, JDBCSQLBuilder.build now renders STARTS_WITH/ENDS_WITH/CONTAINS from the raw literal value through the same escapeSql.

With this fix every literal pushed through compileValue (=, <>, <, <=, >, >=, IN, ...) can be parsed correctly.

Why are the changes needed?

Fix the issue that WHERE c = 'a\b' was pushed to MySQL as `c` = 'a\b', which MySQL parses as `c` = 'a<backspace>', silently dropping the matching row (wrong results).
This is the comparison/IN sibling of SPARK-57332, which fixed only the LIKE family. Standard-SQL dialects are unaffected.

Does this PR introduce any user-facing change?

Yes - fixing JDBC pushdown for string literals with escape backslash for IN/comparison.

How was this patch tested?

Added UT cases

Was this patch authored or co-authored using generative AI tooling?

Yes. Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant